<?php
// +----------------------------------------------------------------------
// | 齐力众信
// +----------------------------------------------------------------------
// | htto://www.qlzhx.com
// +----------------------------------------------------------------------
// | Author: 苏明煌  < qq23025079@126.com >
// +----------------------------------------------------------------------


namespace Addons\Video;
use Common\Controller\Addon;

/**
 * 视频插件
 * @time 2014-09-25
 */
 
 class VideoAddon extends Addon {
 	
	
	# 信息
	public $info = array(
		'name'=>'Video',
		'title'=>'视频插件',
		'description'=>'视频组件',
		'status'=>1,
		'author'=>'smh',
		'version'=>'0.1'
	);
	
	// 判断是否加载过
	static private $is_load = 0;
	
	
	/**
	 * 显示视频插件
	 * @param array $param  array('file'=>'文件地址','width'=>600,'height'=>400)
	 * @example {:hook('showVideo',array('file'=>'文件地址'))}
	 * @return void
	 */
	public function showVideo ( $param )
	{
		/*
		 * 一个页面调用多次，只加载一次js
		 */
		$load = ++ self::$is_load;
		
		if( ! isset( $param['width'] ) )
			$param['width'] = 507;
		
		if( ! isset( $param['height'] ) )
			$param['height'] = 208;
		
		$this->assign( compact( 'load', 'param') );
		
		$this->display('showVideo');
	}
	
	
	# 安装
	public function install ()
	{
		$model = M('hooks');
		
		$add = array(
			'name' => 'showVideo',
			'description' => '视频组件',
			'type' => '1',
			'update_time' => NOW_TIME,
			'addons' => 'Video'
			
		);
		
		$install = $model->add($add);
			
		return $install;
	}
	
	# 卸载
	public function uninstall ()
	{
		
		$model = M('hooks');
		
		$uninstall = $model->where( array('name'=>'showVideo', 'addons'=>'Video') )->delete();
		
		return $uninstall;
	}
 }
